Ext.app.REMOTING_API.enableBuffer = 100;
Ext.Direct.addProvider(Ext.app.REMOTING_API);
Ext.Container.prototype.bufferResize = false;
Ext.form.Field.prototype.msgTarget = 'side';

// Esto es para ver la descripcioón de las excepciones del server en una ventana
Ext.Direct.on('exception', function(e) {
	Ext.Msg.show({
	   title	:'Error!',
	   msg		: e.message,
	   buttons	: Ext.Msg.OK,
	   icon		: Ext.MessageBox.ERROR
	});
});

//Asterisco en los campos obligatorios
Ext.apply(Ext.layout.FormLayout.prototype, {
	originalRenderItem 	: Ext.layout.FormLayout.prototype.renderItem,
	renderItem			: function(c, position, target){
		if(c && !c.rendered && c.isFormField && c.fieldLabel && c.allowBlank === false && !c.disabled)
			c.fieldLabel = c.fieldLabel + "<span style=\"color:red;\" ext:qtip=\"Este campo es obligatorio.\"> * </span>";
		this.originalRenderItem.apply(this, arguments);
	}
});

// remove loading box
var loadingMask_remove = function(){
	var loading = Ext.get('loading');
	var mask = Ext.get('loading-mask');
	mask.setOpacity(.8);
	mask.shift({
		xy:loading.getXY(),
		width:loading.getWidth(),
		height:loading.getHeight(), 
		remove:true,
		duration:1,
		opacity:.3,
		easing:'bounceOut',
		callback : function(){
			loading.fadeOut({duration:.2,remove:true});
		}
	});
};

var loadingMask_setMsg = function(msg){
	document.getElementById('loading-indicator').innerHTML = msg;
};

var failure_message = function(form,action) { 
	var message = 'Error en la transaccion, comuniquese con el Administrador.';
	if(action && action.result && action.result.msg) 
		message = action.result.msg;
    else if(action && action.result && action.result.message)
        message = action.result.message;
    else if( form && form.result && form.result.msg)
        message = form.result.msg;
    else if( form && form.result && form.result.message)
        message = form.result.message;
    
	Ext.Msg.alert('Transaccion', message);
}

Ext.namespace('Ext.ux');

Ext.ux.PageSizePlugin = function() {
    Ext.ux.PageSizePlugin.superclass.constructor.call(this, {
        store	: new Ext.data.SimpleStore({
            fields	: ['text', 'value'],
            data	: [['5', 5], ['10', 10], ['15', 15], ['20', 20], ['25', 25], ['30', 30]]
        }),
        mode			: 'local',
        displayField	: 'text',
        valueField		: 'value',
        editable		: false,		
        allowBlank		: false,
        triggerAction	: 'all',
        width			: 40
    });
};

Ext.extend(Ext.ux.PageSizePlugin, Ext.form.ComboBox, {
    init: function(paging) {
        paging.on('render', this.onInitView, this);
    },
    
    onInitView: function(paging) {
        paging.add('-',
            this,
            'Registros por Página'
        );
        this.setValue(paging.pageSize);
        this.on('select', this.onPageSizeChanged, paging);
    },
    
    onPageSizeChanged: function(combo) {
        this.pageSize = parseInt(combo.getValue());
        this.doLoad(0);
    },
	lazyRender: true,
	lazyInit: true
});

var page_size = 20;